//package com.example.config;
//
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//
///**
// * 多数据源配置类
// *
// * @author chenye
// * @date 2019-02-13 11:56
// */
//@Configuration
//@MapperScan(basePackages = "com.example.dao.third.**",
//        sqlSessionTemplateRef = "thirdSqlSessionTemplate")
//public class ThirdDataSourceConfig {
//
//    @Value("${mybatis.third.mapper-locations}")
//    private String thirdMapperPath;
//
//    @Bean(name = "thirdDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.third")
//    public DataSource thirdDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "thirdSqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory(@Qualifier("thirdDataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//        sqlSessionFactoryBean.setDataSource(dataSource);
//        Resource[] resources = new PathMatchingResourcePatternResolver().getResources(thirdMapperPath);
//        sqlSessionFactoryBean.setMapperLocations(resources);
//        return sqlSessionFactoryBean.getObject();
//    }
//
//    @Bean(name = "thirdTransactionManager")
//    public DataSourceTransactionManager transactionManager(@Qualifier("thirdDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Bean(name = "thirdSqlSessionTemplate")
//    public SqlSessionTemplate sqlSessionTemplate(@Qualifier("thirdSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//}